--
libwebp-dev
Overview
libwebp-dev is the development package for libwebp, the reference library for encoding and decoding the WebP image format. It installs header files, static libraries (where provided), pkg-config metadata, and related build artifacts needed to compile software that links against libwebp.
History
- WebP emerged from the need to reduce image transfer size on the web while maintaining acceptable visual quality.
- The reference encoder/decoder library (libwebp) became the common integration point for server-side image pipelines, desktop tools, and language bindings.
Adoption
Commonly used in:
- Image processing services that generate or optimize WebP assets
- Native applications or CLI tools that need WebP encode/decode support
- Build environments compiling dependencies such as graphics libraries, media frameworks, or image manipulation tools
Maintainer
Maintained by the WebP project/community.
Best when to use
- You are compiling software that needs to link against libwebp
- You need WebP headers and
pkg-configfiles for build systems (CMake, Meson, Autotools) - You are building language bindings or native extensions that require WebP support
Not suitable when
- You only need WebP tools at runtime (install the runtime/tools packages instead)
- You do not compile anything (development headers are unnecessary)
- You require a different WebP implementation for policy reasons (rare; most stacks use libwebp)
Compatibility notes
-
Package naming differs by distribution:
- Debian/Ubuntu:
libwebp-dev - Fedora/RHEL family: typically
libwebp-devel - Arch: typically
libwebp
- Debian/Ubuntu:
-
Some distributions split tools (
cwebp,dwebp) into separate packages. -
Cross-compiling may require the target architecture variant (for example,
:arm64multiarch packages on Debian/Ubuntu).
What it provides
libwebp-dev (or the equivalent -devel package) typically includes:
- Headers (for example:
webp/decode.h,webp/encode.h,webp/mux.h,webp/demux.h) - Libraries (shared and/or static)
pkg-configmetadata (commonlylibwebp.pc, plus optionallibwebpmux.pc,libwebpdemux.pc)
Useful when your build needs:
-Iinclude paths for headers-L/-llibrary flags- Version detection via
pkg-config --modversion
Installation
- Debian/Ubuntu
- Fedora/RHEL family
- Arch
- macOS
sudo apt update
sudo apt install libwebp-dev
sudo dnf install libwebp-devel
sudo pacman -S libwebp
brew install webp
On macOS, Homebrew typically provides both the library and CLI tools in one formula.
Verify installation (read-only)
Check pkg-config visibility:
pkg-config --modversion libwebp
pkg-config --cflags libwebp
pkg-config --libs libwebp
Confirm headers exist:
ls -la /usr/include/webp 2>/dev/null || true
Confirm libraries exist (paths vary by distro):
ldconfig -p 2>/dev/null | grep -i webp || true
Common build usage
Compile a simple program (using pkg-config)
Create webp_version.c:
#include <stdio.h>
#include <webp/decode.h>
int main(void) {
printf("WebP decoder ABI version: %d\n", WebPGetDecoderVersion());
return 0;
}
Compile and link:
cc webp_version.c $(pkg-config --cflags --libs libwebp) -o webp_version
./webp_version
Link demux/mux components
Some features (animations, container parsing) use additional libs:
libwebpdemuxlibwebpmux
Detect availability:
pkg-config --exists libwebpdemux && echo "libwebpdemux available" || echo "libwebpdemux not found"
pkg-config --exists libwebpmux && echo "libwebpmux available" || echo "libwebpmux not found"
Link example (if available):
cc mytool.c $(pkg-config --cflags --libs libwebp libwebpdemux libwebpmux) -o mytool
CMake integration
Minimal CMakeLists.txt using pkg-config:
cmake_minimum_required(VERSION 3.16)
project(webp_example C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WEBP REQUIRED IMPORTED_TARGET libwebp)
add_executable(webp_version webp_version.c)
target_link_libraries(webp_version PRIVATE PkgConfig::WEBP)
Build:
cmake -S . -B build
cmake --build build
./build/webp_version
CLI tools (runtime utilities)
Many systems provide WebP tools (may be packaged separately). Common tools include:
cwebp: encode images to WebPdwebp: decode WebP to another formatwebpmux: manipulate WebP container (including animations)gif2webp: convert GIF to animated WebPimg2webp: build animated WebP from frames
Check which tools are installed (read-only)
command -v cwebp dwebp webpmux gif2webp img2webp 2>/dev/null || true
Encode example
cwebp -q 80 input.png -o output.webp
Decode example
dwebp input.webp -o output.png
libwebp-dev is primarily for compilation and linking. If you only need cwebp/dwebp, install the WebP tools/runtime package for your distribution.
Practical use cases
Build a dependency with WebP support
Common patterns include enabling WebP support in a larger project that detects it via pkg-config:
pkg-config --modversion libwebp
Then rebuild your dependency after installing libwebp-dev (or equivalent).
Add WebP support to a custom image pipeline
Typical native pipeline steps:
- Decode source input (JPEG/PNG)
- Transform (resize/crop/colorspace)
- Encode to WebP with chosen quality and mode
When integrating libwebp directly, keep strict resource limits in place (see Security notes).
Troubleshooting
fatal error: webp/decode.h: No such file or directory
Cause: headers not installed or include path not set.
Fixes:
- Ensure the development package is installed (
libwebp-dev/libwebp-devel) - Use
pkg-config --cflags libwebpin your compiler invocation - Verify headers location:
pkg-config --cflags libwebp
ls -la /usr/include/webp 2>/dev/null || true
Linker errors: undefined reference to ...
Cause: missing -lwebp (or related libs), or wrong link order.
Fix:
- Prefer
pkg-config --libs libwebprather than hand-writing flags - If using mux/demux APIs, link those libraries too:
pkg-config --libs libwebp libwebpdemux libwebpmux
pkg-config: command not found
Install pkg-config:
- Debian/Ubuntu:
sudo apt install pkg-config
- Fedora/RHEL:
sudo dnf install pkgconf-pkg-config
Version mismatch in build containers
Cause: builder image has headers but runtime image lacks the shared library (or uses a different version).
Fix:
- Install the runtime lib package in the runtime image (not just
-dev) - Keep build and runtime images aligned to the same distribution release where possible
Security notes
Image decoders are a common source of memory-safety vulnerabilities. When decoding untrusted WebP files, run the decode pipeline with resource limits (CPU time, memory, and output pixel dimensions) and keep libwebp updated via OS security patches.
Operational safeguards:
- Enforce maximum input size and maximum decoded dimensions (width × height)
- Apply process-level limits in services that decode user uploads (cgroups, container limits, ulimits)
- Prefer isolating image decoding in a separate process or sandbox when handling public uploads
Quick reference
| Task | Command |
|---|---|
| -- | - |
| Install (Debian/Ubuntu) | sudo apt install libwebp-dev |
| Install (Fedora/RHEL) | sudo dnf install libwebp-devel |
| Check installed version | pkg-config --modversion libwebp |
| Show compile flags | pkg-config --cflags libwebp |
| Show link flags | pkg-config --libs libwebp |
| Compile example | cc app.c $(pkg-config --cflags --libs libwebp) -o app |
| Check tools | command -v cwebp dwebp webpmux |
| Encode WebP | cwebp -q 80 input.png -o output.webp |
| Decode WebP | dwebp input.webp -o output.png |